package com.changgou.seckill.controller;

import com.changgou.entity.Result;
import com.changgou.entity.StatusCode;
import com.changgou.seckill.config.TokenDecode;
import com.changgou.seckill.pojo.SeckillGoods;
import com.changgou.seckill.service.SecKillGoodsService;
import com.changgou.seckill.service.SecKillOrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/seckillorder")
public class SecKillOrderController {

    @Autowired
    private TokenDecode tokenDecode;

    @Autowired
    private SecKillOrderService secKillOrderService;

    @RequestMapping("/add")
    public Result add (@RequestParam("time")String time,@RequestParam("id")Long id ){

        String username = tokenDecode.getUserInfo().get("username");
        boolean result = secKillOrderService.add(time, id, username);
        if(result){
            return new Result(true,StatusCode.OK,"秒杀下单成功");
        }else {
            return new Result(false,StatusCode.ERROR,"秒杀下单失败");
        }


    }

}
